'use strict';

let fs = require('fs');
let path = require('path');

let http = require('http');

let workspaceFolder = path.resolve('.');


// let server = http.createServer((req, res) => {
//     res.write('<head><meta charset="utf-8"/></head>');
//     let reqPath = req.url;
//     if (reqPath !== '/favicon.ico') {
//         let fullPath = path.join(workspaceFolder, reqPath);
//         let log = fs.readdirSync(fullPath);
//         log.forEach(item => {
//             if (item === 'index.html') {
//                 let fileName = path.join(fullPath, item);
//                 fs.createReadStream(fileName).pipe(res);
//             }
//         })

//     }
// })
// server.listen(3050);
// console.log('Server running at http://127.0.0.1:3050/');

let server = http.createServer((req,res)=> {
    res.write('<head><meta charset="utf-8"/></head>');
    let reqPath = req.url;

    if(reqPath!=='/favicon.ico'){
        let fullPath = path.join(workspaceFolder,reqPath);
        let log = fs.readdirSync(fullPath);

        log.forEach(item=>{
            if(item==='index.html' || item === 'z1.html'){
                let fileName = path.join(fullPath,item);
                console.log(fileName);
                fs.createReadStream(fileName).pipe(res);
            }
        })
    }
}).listen(1475);

console.log('Server running at http://127.0.0.1:1475/');
